/* compute a basic ones-compliment checksum */

/* Copyright (C) 2009 David Zanetti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; version 2 of the License.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#define CHECKSUM_H

/* note, we could extend this to use the hardware checksum feature 
 * of the enc28j60, but we're doing it in software since it's fast */

/* computer the checksum of the packet covering only len */
uint16_t checksum(uint8_t *pkt, uint16_t len);

/* UDP version of checksum, expects some IP variables for psueoheader */
uint16_t udp_checksum(uint8_t *pkt, uint16_t len, uint32_t src,
                      uint32_t dst);

/* compute a partial checksum. This expects len bytes to be processed,
 * and giving -1 will finish the checksum */
uint32_t checksum_partial(uint8_t *pkt, int16_t len, uint32_t sum);
